# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

pkgname=eslint
pkgver=8.54.0
pkgrel=1
pkgdesc='An AST-based pattern checker for JavaScript'
arch=('any')
url='https://eslint.org'
license=('MIT')
depends=('acorn' 'nodejs')
makedepends=('git' 'npm' 'rsync')
options=('!emptydirs')
source=("git+https://github.com/$pkgname/$pkgname.git#tag=v$pkgver")
b2sums=('SKIP')

prepare() {
  cd $pkgname
  npm install
}

check() {
  cd $pkgname
  node Makefile.js mocha
}

package() {
  local mod_dir=/usr/lib/node_modules/$pkgname
  install -d "$pkgdir"/usr/bin
  ln -s $mod_dir/bin/$pkgname.js "$pkgdir"/usr/bin/$pkgname

  cd $pkgname
  npm prune --production

  install -Dt "$pkgdir"/$mod_dir/bin bin/$pkgname.js
  rsync -r --exclude=.cache --exclude=.package-lock.json conf lib messages \
    node_modules package.json "$pkgdir"/$mod_dir
  install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname README.md
  install -Dm644 -t "$pkgdir"/usr/share/licenses/$pkgname LICENSE

  # Experimental dedup
  rm -r "$pkgdir"/$mod_dir/node_modules/acorn
}
